const fs = require('fs');
const http = require('http');
const { url } = require('inspector');

const server = http.createServer((request, response) => {
    const { url, method, headers } = request;
    if (method === 'GET' && url === '/') {
        console.log(1111);
        fs.readFile('index.html', (err, data) => {
            response.statusCode = 200
            response.setHeader('Content-Type', 'text/html')
            response.end(data);
        })
    } else if (method === 'GET' && url === '/index') {
        response.end(JSON.stringify({ name: '小吴' }))
    } else if (method === 'GET' && headers.accept.indexOf('image/*') !== -1) {
        fs.createReadStream('./' + url).pipe(response)
    }
})

server.listen(3000)